﻿
layui.use('upload', function () {
    var $ = layui.jquery
    , upload = layui.upload;

    //拖拽上传
    upload.render({
        elem: '#uploadPicture'
      , url: Root + 'FZUser/UploadFile' //改成您自己的上传接口
      , done: function (res) {
          layer.msg('上传成功');
          layui.$('#uploadView').removeClass('layui-hide').find('img').attr('src', "data:image/" + res.Extension + ";base64," + res.Content);
          //console.log(res)
          if (res.SubmitResult)
              $('#editorPanelButtons').show();
          else
              $('#editorPanelButtons').hide();
      }
    });

});

$(function () {
    $('#Save').click(function () {
        var headImg = $('#txtHeadImg').val();
        if (headImg == "") {
            dialog.warning('请上传头像图片！');
            return false;
        }

        $.ajax({
            type: "post",
            url: PSIRoot + 'PSIUser/SaveAvatar',
            data: { headImg: headImg },
            success: function (data) {
                if (data.SubmitResult) {
                    toastr.success("头像保存成功!");
                } else {
                    dialog.danger('操作失败！Error Message:' + data.Message);
                }
            },
            error: function () {
                dialog.danger('操作失败！请重试或者联系管理员');
            },
            complete: function () {

            }
        });
    });
});

//图片变化更新 系统中头像
function changeLoginUserHeadImg() {
    var headImg = $('#txtHeadImg').val();
    $('#loginUserHeadImg', window.parent.document).attr('src', headImg);
}

